﻿using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using AutoMapper;
using TRACv2.Common.Enumerations;
using TRACv2.Domain.DTO;
using TRACv2.Domain.Interfaces.IRepository;
using TRACv2.Domain.Interfaces.IService;

//Author: Morgan William Davis III
//Project: TRAC Ticket Manager v2
//Date: 14 Mar 2014

namespace TRACv2.Domain.Services
{
    public class TicketService : ITicketService
    {
        #region [ Fields ]

        private readonly ITicketRepository _ticketRepository;

        #endregion

        #region [ Constructor ]

        public TicketService(ITicketRepository ticketRepository)
        {
            _ticketRepository = ticketRepository;
        }

        #endregion

        #region [ Methods ]

        public List<TicketDTO> GetAll(bool filter, int? contact = null, int? creator = null, int? assigned = null,
            Issue? issue = null, Priority? priority = null, Status? status = null, DateTime? start = null, DateTime? end = null)
        {
           var returnList = Mapper.Map<List<TicketDTO>>(_ticketRepository.GetAll(filter, contact, creator, assigned, issue, priority,
                status, start, end));

            return returnList;
        }

        public TicketDTO GetByNumber(string number)
        {
            var returnTicket = _ticketRepository.GetByNumber(number);

            return returnTicket;
        }

        public void Add(TicketDTO ticket)
        {
            _ticketRepository.Add(ticket);
        }

        public void Update(TicketDTO ticket)
        {
            _ticketRepository.Update(ticket);
        }

        public void Delete(TicketDTO ticket)
        {
            _ticketRepository.Delete(ticket);
        }

        public void Archive(TicketDTO ticket)
        {
            _ticketRepository.Archive(ticket);
        }

        #endregion
    }
}
